package com.zdsoft.blp.zongbuju.shouye.taoshihui.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.zdsoft.blp.R;
import com.zdsoft.blp.gongyong.application.MyApp;
import com.zdsoft.blp.zongbuju.shouye.taoshihui.entity.Goods;

import java.util.List;

/**
 * Created by pc on 2016/9/1.
 */
public class ZgridViewAdapter extends BaseAdapter {
    private List<Goods> lists;
    private Context context;

    public ZgridViewAdapter(List<Goods> lists, Context context) {
        this.lists = lists;
        this.context = context;
    }

    @Override
    public int getCount() {
        return lists.size();
    }

    @Override
    public Object getItem(int position) {
        return lists.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder=new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.tsh_zgvitem, null);
            holder.iv = (ImageView) convertView.findViewById(R.id.iv);
            holder.tv_title = (TextView) convertView.findViewById(R.id.tv_title);
            holder.tv_yPrice = (TextView) convertView.findViewById(R.id.tv_yPrice);
            holder.tv_xPrice = (TextView) convertView.findViewById(R.id.tv_xPrice);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        MyApp.setImage(lists.get(position).getPicPath(),holder.iv);
        holder.tv_title.setText(lists.get(position).getGoodsName().toString());
        holder.tv_yPrice.setText(lists.get(position).getOldPrice()+"元");
        holder.tv_yPrice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        holder.tv_xPrice.setText(lists.get(position).getDiscountPrice()+"");
        return convertView;
    }

    class ViewHolder {
        ImageView iv;
        TextView tv_title;
        TextView tv_yPrice;
        TextView tv_xPrice;
    }
}
